package com.hnichr.ump.common.talent.library.handle;

import com.hnichr.ump.common.talent.library.entity.EducationInfo;
import com.hnichr.ump.common.talent.library.entity.SchoolList;
import org.apache.commons.lang3.StringUtils;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class SchoolTypeHandle {
    private List<SchoolList> schools;


    public void init(List<SchoolList> allSchoolList){
        schools = allSchoolList.stream().sorted(Comparator.comparing(SchoolList::getSchoolType).reversed()).collect(Collectors.toList());
    }

    public String classify(List<EducationInfo> allEduList){
        List<EducationInfo> eduList = allEduList.stream().filter(p-> !p.getDelFlag() &&p.getEduLevel()>=4).sorted(Comparator.comparing(EducationInfo::getEduLevel).reversed()).collect(Collectors.toList());
        for(EducationInfo edu:eduList){
            for(SchoolList school:schools){
                if(StringUtils.indexOf(edu.getSchoolName(),school.getSchoolName())>=0){
                    //虽然匹配上，但是可能是中国大学的二级学院
                    if(StringUtils.indexOf(edu.getSchoolName(),"学院")>=0&&StringUtils.equals(school.getRegion(),"中国")){
                        continue;
                    }
                    return school.getSchoolType();
                }
            }
        }
        return "0";
    }
}
